package com.hzit.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.hzit.manager.service.IContentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 广告管理Controller
 *
 * @author wf
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/content")
public class ContentController extends BaseController
{
    @Autowired
    private IContentService contentService;

    /**
     * 查询广告管理列表
     */
        @GetMapping("/list")
    public TableDataInfo list(Content content)
    {
        startPage();
        List<Content> list = contentService.selectContentList(content);
        return getDataTable(list);
    }

    /**
     * 导出广告管理列表
     */
    @Log(title = "广告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Content content)
    {
        List<Content> list = contentService.selectContentList(content);
        ExcelUtil<Content> util = new ExcelUtil<Content>(Content.class);
        util.exportExcel(response, list, "广告管理数据");
    }

    /**
     * 根据分类id查询广告列表
     */
    @GetMapping("/findContentsByCateId/{id}")
    public R<List<Content>> findContentsByCateId(@PathVariable("id") Long cateId){
        Content content = new Content();
        content.setCategoryId(cateId);
        List<Content> contentList = contentService.selectContentList(content);
        return R.ok(contentList);
    }
    /**
     * 获取广告管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(contentService.selectContentById(id));
    }

    @GetMapping("/findById/{id}")
    public R<Content> findById(@PathVariable("id") Long id){
        return R.ok(contentService.selectContentById(id));
    }

    /**
     * 新增广告管理
     */
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Content content)
    {
        return toAjax(contentService.insertContent(content));
    }

    /**
     * 修改广告管理
     */
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Content content)
    {
        Content con = contentService.edit(content);
        return con != null ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 删除广告管理
     */
        @Log(title = "广告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contentService.deleteContentByIds(ids));
    }
}
